<template>
    <div id="home">
        <el-container>
            <el-aside width="200px">
                <SideMenu></SideMenu>
            </el-aside>
            <el-container>
                <el-header>
                    <strong>Spring Security安全框架</strong>
                    <div class="header-right">
                        <el-avatar size="medium" :src="form.avatar"></el-avatar>
                        <el-dropdown>
                            <span class="el-dropdown-link">
                                {{ form.username }}<i class="el-icon-arrow-down el-icon--right"></i>
                            </span>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item divided>个人中心</el-dropdown-item>
                                <el-dropdown-item @click.native="logout" divided>退出</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                        <el-link href="https://mp.csdn.net/mp_blog/manage/article?spm=1011.2124.3001.5298">CSDN笔记
                        </el-link>
                        <el-link href="https://gitee.com/">Gitee仓库</el-link>
                    </div>
                </el-header>
                <el-main class="el-main">
                    <div style="margin: 0 15px;">
                        <Tabs></Tabs>
                    </div>
                    <router-view/>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>

<script>
import SideMenu from "@/views/SideMenu";
import {getUserInfo, logout} from "@/api/login";
import Tabs from "@/views/Tabs";

export default {
    name: "Home",
    components: {Tabs, SideMenu},
    data() {
        return {
            form: {
                id: null,
                username: null, // 用户名
                avatar: null, // 头像
            }
        }
    },
    mounted() {
        this.getUserInfo();
    },
    methods: {
        getUserInfo(){
            getUserInfo().then(res =>{
                Object.assign(this.form, res.data.data);
            })
        },
        logout(){
            logout().then(res =>{
                console.log(res.data.data)
                this.$store.commit('RESET_STATE')
                this.$store.commit('RESET_TAB_STATUS')
                this.$router.push('/login')
            })
        }
    },
}
</script>

<style lang="less" scoped>
.el-container {
    margin: 0;
    padding: 0;
    height: 100vh;

    .header-right {
        width: 260px;
        float: right;
        display: flex;
        justify-content: space-around;
        align-items: center;
        font-weight: bold;
    }
}

.el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    text-align: center;
    line-height: 60px;
}

.el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
}

.el-main {
    background-color: #E9EEF3;
    color: #333;
    //text-align: center;
    padding: 0;
}

body > .el-container {
    margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
    line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
    line-height: 320px;
}

.el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
}

.el-icon-arrow-down {
    font-size: 12px;
}

</style>
